package ${basePackageName}.domain.mybatis.entity;

<#if common>
import com.zy.explore.common.infrastructure.base.mybatis.MpBaseEntity;
import com.zy.explore.common.infrastructure.util.StrUtil;
<#else>
import ${basePackageName}.infrastructure.base.mybatis.MpBaseEntity;
import ${basePackageName}.infrastructure.util.StrUtil;
</#if>
import ${basePackageName}.interfaces.frm.${tableClassNamePrefix}QueryFrm;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

import javax.persistence.Table;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import java.util.Date;
import org.springframework.util.StringUtils;
<#if pkType != 'String'>
import java.util.stream.Collectors;
</#if>

/**
 * 表(${tableName})对应的Mybatis ORM实体对象
 *
 * @author ${authorName}
 * @date ${dateTime}
 */
@Slf4j
@Entity
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TableName("${tableName}")
@Table(name = "${tableName}")
public class <#if prefixMp??>${prefixMp}</#if>${tableClassNamePrefix} extends MpBaseEntity<<#if prefixMp??>${prefixMp}</#if>${tableClassNamePrefix}, ${pkType}> {

<#list tableColumns as column>
    <#if column.isPk>
    /**
     * 主键
     */
    @Id
    @Column(name = "${column.columnName}")
    private ${column.propType} ${column.propName};
    <#else>
    /**
     * ${(column.columnComment != '')? string('${column.columnComment}','TODO 补充字段注释')}
     */
    @Column(name = "${column.columnName}")
    private ${column.propType} ${column.propName};
    </#if>

</#list>

    /**
     * 组装查询条件
     *
     * @param frm 请求参数
     * @return {@link Wrapper<<#if prefixMp??>${prefixMp}</#if>${tableClassNamePrefix}> }
     */
    public static Wrapper<<#if prefixMp??>${prefixMp}</#if>${tableClassNamePrefix}> getWrapper(${tableClassNamePrefix}QueryFrm frm) {
        // TODO 请按实际需求组装查询条件
        log.warn("TODO 请按实际需求组装查询条件");
        if (frm.getPageNum() == null || frm.getPageNum() <= 0) {
            frm.setPageNum(1);
        }
        if (frm.getPageSize() == null || frm.getPageSize() <= 0) {
            frm.setPageSize(10);
        }
        Wrapper<<#if prefixMp??>${prefixMp}</#if>${tableClassNamePrefix}> wrapper = new EntityWrapper<>();
    <#list tableColumns as column>
        <#if column.propType == 'Integer' || column.propType == 'Long' || column.propType == 'Float' || column.propType == 'Double' || column.propType == 'Boolean'>
        if(frm.get${column.firstUpperPropName}() != null) {
            wrapper.eq(StrUtil.humpToUnderline("${column.propName}"), frm.get${column.firstUpperPropName}());
        }
        <#elseif column.propType == 'Date'>
        if(!StringUtils.isEmpty(frm.get${column.firstUpperPropName}Begin())) {
            wrapper.ge(StrUtil.humpToUnderline("${column.propName}"), frm.get${column.firstUpperPropName}Begin());
        }
        if(!StringUtils.isEmpty(frm.get${column.firstUpperPropName}End())) {
            wrapper.le(StrUtil.humpToUnderline("${column.propName}"), frm.get${column.firstUpperPropName}End());
        }
        <#elseif column.propType == 'String'>
        if (!StringUtils.isEmpty(frm.get${column.firstUpperPropName}())) {
        wrapper.like(StrUtil.humpToUnderline("${column.propName}"), frm.get${column.firstUpperPropName}() + "%");
        }
        </#if>
    </#list>
        return wrapper;
    }
}